package com.yuanduan.mplus.presenter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yuanduan.mplus.R;
import com.yuanduan.mplus.model.entity.DriveRecordEntity;

import java.util.List;

/**
 * Created by cj on 2016/6/24.
 * Email:781806481@qq.com
 */
public class DriveRecordAdapter extends BaseAdapter {
    private List<DriveRecordEntity> datas;
    private Context context;
    public DriveRecordAdapter(Context context,List<DriveRecordEntity> lists) {
        this.context=context;
        datas=lists;
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DriveRecordEntity entity=datas.get(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null){
            view= LayoutInflater.from(context).inflate(R.layout.driverecord_listview,null);
            viewHolder=new ViewHolder();
            viewHolder.tv1= (TextView) view.findViewById(R.id.driverecord_tv_1);
            viewHolder.tv2= (TextView) view.findViewById(R.id.driverecord_tv_2);
            viewHolder.tv3= (TextView) view.findViewById(R.id.driverecord_tv_3);
            viewHolder.tv4= (TextView) view.findViewById(R.id.driverecord_tv_4);
            view.setTag(viewHolder);
        }else{
            view=convertView;
            viewHolder= (ViewHolder) view.getTag();
        }
        viewHolder.tv1.setText(entity.getCarNumber());
        viewHolder.tv2.setText(entity.getStartTime());
        viewHolder.tv3.setText(entity.getEndTime());
        viewHolder.tv4.setText(entity.getDistance());
        return view;
    }
    class ViewHolder{
        TextView tv1;
        TextView tv2;
        TextView tv3;
        TextView tv4;
    }
}
